# w+ 读写权限, 清空文件在写入，如果没有文件，创建新文件
# with open('data1.txt', 'w+', encoding='utf-8') as f:
#     print(f.write('hogwarts 2022'))
# #查看关闭状态
# print(f.closed)

# r+ 读写权限，替换原来的内容
# with open('data1.txt', 'r+', encoding='utf-8') as f:
#     print(f.write('\nhogwarts 2022'))
# #查看关闭状态
# print(f.closed)

# a+ 读写权限 会在最末尾的位置，追加数据，不清空原来的内容
with open('data1.txt', 'a+', encoding='utf-8') as f:
    print(f.write('\nhogwarts 2022'))
#查看关闭状态
print(f.closed)